package com.lfnyxy.service.org.imp;

import com.lfnyxy.dao.org.SysRoleDao;
import com.lfnyxy.dto.DropVo;
import com.lfnyxy.entity.org.SysRoleEntity;
import com.lfnyxy.query.org.SysRoleQuery;
import com.lfnyxy.service.org.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysRoleServiceImp implements SysRoleService {
    @Autowired
    public SysRoleDao sysRoleDao;

    public int CreateItem(SysRoleEntity entity) {
        if (entity != null) {
            sysRoleDao.CreateItem(entity);
            return entity.getId();
        } else {
            return 0;
        }
    }

    public int UpdateItem(SysRoleEntity entity) {
        if (entity != null) {
            sysRoleDao.UpdateItem(entity);
            return entity.getId();
        } else {
            return 0;
        }
    }

    public List<SysRoleEntity> QueryPageList(SysRoleQuery query) {
        int count = sysRoleDao.QueryPageListCount(query);
        query.setTotal(count);
        if (count > 0) {
            return sysRoleDao.QueryPageList(query);
        }
        return null;
    }

    public List<DropVo> QueryDrop(SysRoleQuery query) {
        return sysRoleDao.QueryDrop(query);
    }

    public List<SysRoleEntity> QueryAll() {
        return sysRoleDao.QueryAll();
    }

    public SysRoleEntity QueryItem(int Id) {
        if (Id > 0) {
            return sysRoleDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return sysRoleDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(SysRoleEntity entity) {
        if (entity != null) {
            return sysRoleDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}